package ModelLayer;


/**
 * Write a description of class StaffMember here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class StaffMember extends Person
{
    private String login;
    private String password;
    private int salary;
    private boolean is_manager;
    private boolean is_owner;
    private int how_much_has_sold;
    private String orders_serviced;
    /**
     * Constructor for objects of class StaffMember
     * It assignes provided data to attributes of StaffMember class,
     * both those generic of this class as well as those inherited from Person class
     */
    public StaffMember(String i_id, String i_name, String i_phone_nr, String i_address, String i_postal_code, String i_city, String i_login, String i_password, int i_salary, boolean i_is_manager, boolean i_is_owner, int i_how_much_has_sold, String i_orders_serviced)
    {
        super(i_id, i_name, i_phone_nr, i_address, i_postal_code, i_city);
        login = i_login;
        password = i_password;
        salary = i_salary;
        is_manager = i_is_manager;
        is_owner = i_is_owner;
        how_much_has_sold = i_how_much_has_sold;
        orders_serviced = i_orders_serviced;
    }
    
    /**********************************************************************************GETTERS**********************************************************************************************/
   
    /**
     * Returns StaffMember's login.
     */
    public String get_login()
    {
        return login;
    }
    
    /**
     * Returns StaffMember's salary.
     */
    public int get_salary()
    {
        return salary;
    }
    
    /**
     * Returns StaffMember's password.
     */
    public String get_password()
    {
        return password;
    }
    
    /**
     * Returns true if StaffMemeber is an owner.
     * Returns false otherwise.
     */
    public boolean get_is_owner()
    {
        return is_owner;
    }
    
    /**
     * Returns true if StaffMemeber is a manager.
     * Returns false otherwise.
     */
    public boolean get_is_manager()
    {
        return is_manager;
    }
    
    /**
     * Returns the total amount of money for which the goods sold by this StaffMember were sold.
     */
    public int get_how_much_has_sold()
    {
        return how_much_has_sold;
    }
    
    /**
     * Returns ID's of the orders serviced by this StaffMember, separated with spaces
     */
    public String orders_serviced()
    {
        return orders_serviced();
    }
    
    /**********************************************************************************SETTERS**********************************************************************************************/
    
    /**
     * Changes StaffMember's name with provided input.
     */
    public void set_login(String input)
    {
        login = input;
    }
    
    /**
     * Changes StaffMember's salary with provided input.
     */
    public void set_salary(int input)
    {
        salary = input;
    }
    
    /**
     * Changes StaffMember's password with provided input.
     */
    public void set_password(String input)
    {
        password = input;
    }
    
    public void set_is_manager(boolean input)
    {
        is_manager = input;
    }
    
    public void set_is_owner(boolean input)
    {
        is_owner = input;
    }
    
    public void increase_total_sales(double new_sales)
    {
        how_much_has_sold += new_sales;
    }
    
    public void add_new_serviced_order(String id)
    {
        if(orders_serviced.equals(""))
        {
            orders_serviced = id;
        }
        else
        {
            orders_serviced += " " + id;
        }
    }
    
    /**********************************************************************************OTHER METHODS**********************************************************************************************/
    
    /**
     * This method returns all attributes of StaffMember as a single String.
     * Attributes are separated with single tabulations.
     */
    
    public String give_string_data()
    {
        return super.give_string_data() + String.format("\t%s\t%s\t%s\t%s\t%s\t%s\t%s",  login, password, salary, is_manager, is_owner, orders_serviced, how_much_has_sold);
    }
    
    public String printable()
    {
        return super.printable() + String.format("Salary:\t\t\t\t%s\nHas sold:\t\t\t%s \nIDs of serviced orders:\t%s", salary, how_much_has_sold, convert_orders_serviced());
    }
    
    private String convert_orders_serviced()
    {
        String all_data = "";
        boolean first = true;
        for(String id : orders_serviced.split(" "))
        {
            if(first)
            {
                all_data += "\t" +  id + "\n";
                first = false;
            }
            else
            {
                all_data += "\t\t\t\t" + id + "\n";
            }
        }
        return all_data;
    }
    
    
         
        
                  
}
